// pages/my/consumeList/consumeList.js
import Http from "../../../utils/api";
const http = new Http;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userConsumeList: [],
    time: '',
    total_price: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let time = year + '-' + month;
    let _time = year + '年' + month + '月';
    this.setData({time:_time});
    this.getUserConsumeList(time);
  },

  getUserConsumeList(time) {
    http.request('user/consume/list',{time}).then((res) => {
      this.setData({userConsumeList: res});
    })
  },

  bindDateChange: function(e) {
    let time = e.detail.value;
    let date = time.split('-');
    let year = date[0];
    let month = 1;
    if(date[1] < 10) {
      month = date[1].slice(-1);
    }else {
      month = date[1];
    }

    time = year + '年' + month + '月';
    let _time = year + '-' + month;
    this.setData({time});
    this.getUserConsumeList(_time);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})